efform_onload = function ()
{
};
/**
 * 查询 方法
 */
button_query_onclick = function() {
	efgrid.submitInqu("ef_grid_result", "ZM", "ZMCC00", "query");
};
/**
 * 新增 方法
 */
button_insert_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		var fdProblemTimeF = grid.getCellValueByColumnName(rows[i], "fdProblemTimeF");
		var fdDeadlineTimeF = grid.getCellValueByColumnName(rows[i], "fdDeadlineTimeF");
		if (getDateValue(fdProblemTimeF) > getDateValue(fdDeadlineTimeF)) {
			EFAlert("发生时间不能晚于解决时间，请重新输入！");
			return;
		}
	}
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCC00", "insert", true);
};

/**
 * 修改 方法
 */
button_update_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdProblemStatus") != "0") {
			EFAlert("只能对草拟的记录进行修改！");
			return;
		}

		var fdProblemTimeF = grid.getCellValueByColumnName(rows[i], "fdProblemTimeF");
		var fdDeadlineTimeF = grid.getCellValueByColumnName(rows[i], "fdDeadlineTimeF");
		if (getDateValue(fdProblemTimeF) > getDateValue(fdDeadlineTimeF)) {
			EFAlert("发生时间不能晚于解决时间，请重新输入！");
			return;
		}
	}
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCC00", "update", true);
};
/**
 * 删除 方法
 */
button_delete_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdProblemStatus") != "0") {
			EFAlert("只能对草拟的记录进行删除！");
			return;
		}
	}

	EFConfirm('你确认要删除吗?', '确认框',
			function(r) {
				if (r)
					efgrid.submitForm("ef_grid_result", "ZM", "ZMCC00",
							"delete", true);
			});
};
/**
 * 上报 方法
 */
button_report_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	if (rows.length > 1) {
		EFAlert("一次只能生效一条记录！", "警告");
		return;
	}
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdProblemStatus") != "0") {
			EFAlert("只能生效草拟状态的记录！", "警告");
			return;
		}
		if (grid.getCellValueByColumnName(rows[i], "fdKeyId") == "") {
			EFAlert("该记录不存在，请先新增后再生效！", "警告");
			return;
		}
	}

	EFConfirm('确认要生效吗?', '确认框',
			function(r) {
				if (r)
					efgrid.submitForm("ef_grid_result", "ZM", "ZMCC00", "report", true);
			});
};
/**
 * 新增行后操作
 */
efgrid_afterAddNewRow = function(grid_id) {
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if (grid_id == "ef_grid_result") {

		var fdCreateDepartmentId = $('#fdCreateDepartmentId').val();
		var fdCreator = $('#fdCreator').val();
		var time = getNowDateTime();// 当前时间

		for (var i = 0; i < rows.length; i++) {
			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
			grid.getBlockData().setCell(rows[i], "fdProblemStatus", "0");// 状态
			grid.getBlockData().setCell(rows[i], "fdSubmitorDepartmentId", fdCreateDepartmentId);// 提出部门
			grid.getBlockData().setCell(rows[i], "fdSubmitor", fdCreator);// 提出人
			grid.getBlockData().setCell(rows[i], "fdProblemTimeF", time);// 发生时间
			grid.getBlockData().setCell(rows[i], "fdDeadlineTimeF", time);// 解决时间
		}
	}
};

/**
 * 加载主表状态字段的颜色
 * @param div_node_html
 * @param row_index
 * @param col_index
 * @param col_value_c
 * @param display_value
 * @param grid_id
 * @returns {String}
 */
efgrid_onCellDisplayReady = function( div_node_html, row_index, col_index, col_value_c, display_value ,grid_id)
{	
   var grid_obj = efgrid.getGridObject(grid_id);
   var columnEname = grid_obj.getColumn(col_index, TYPE_DATA).getEname();
   if( columnEname == "fdProblemStatus"  &&  grid_id=="ef_grid_result")
	{  
	 	var isNewLine = grid_obj.isNewLine(row_index);
        if(!isNewLine)
        {
            var html = "";
            if (col_value_c == "1") html = "<div align=center><font color='blue'>"+display_value+"</font></div>";   
            else if (col_value_c == "2") html = "<div align=center><font color='green'>"+display_value+"</font></div>";   
            else if (col_value_c == "3") html = "<div align=center><font color='red'>"+display_value+"</font></div>";   
            else if (col_value_c == "4") html = "<div align=center><font color='grey'>"+display_value+"</font></div>";   
            else if (col_value_c == "5") html = "<div align=center><font color='orange'>"+display_value+"</font></div>";   
            else html = "<div align=center>"+display_value+"</div>";   
            return html; 
        }else
        {	
            return;
        }
	}	
};

/**
 * 根据传入的String类型的date获取该日期对应的毫秒值，传入的字符串格式为：yyyy-MM-dd HH:mm:ss
 * @param dateStr
 * @returns
 */
function getDateValue(dateStr) {
	var tt = dateStr.split(" ");
	var ttt1 = tt[0].split("-");
	var ttt2 = tt[1].split(":");

	var date1 = new Date(ttt1[0], ttt1[1], ttt1[2], ttt2[0], ttt2[1], ttt2[2]);
	var m1 = date1.getTime();
	return m1;
}

